"""
RAG 相关的请求/响应模型
"""
from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field


class FileUploadResponse(BaseModel):
    """文件上传响应"""
    success: bool
    message: str
    file_id: Optional[str] = None
    file_type: Optional[str] = None
    document_count: Optional[int] = None


class DocumentProcessRequest(BaseModel):
    """文档处理请求"""
    file_path: str = Field(..., description="文件路径")
    file_type: Optional[str] = Field(None, description="文件类型：pdf/txt/docx，不提供则自动识别")
    chunk_size: int = Field(1000, description="文本块大小")
    chunk_overlap: int = Field(200, description="文本块重叠大小")


class DocumentProcessResponse(BaseModel):
    """文档处理响应"""
    success: bool
    message: str
    chunk_count: Optional[int] = None
    document_count: Optional[int] = None


class QuestionRequest(BaseModel):
    """问题请求"""
    question: str = Field(..., description="用户问题")
    top_k: int = Field(5, description="检索文档数量", ge=1, le=20)


class SourceInfo(BaseModel):
    """来源信息"""
    content: str
    source: str
    score: float


class QuestionResponse(BaseModel):
    """问题响应"""
    answer: str = Field(..., description="AI回答")
    query: str = Field(..., description="用户问题")
    sources: List[SourceInfo] = Field(default_factory=list, description="参考来源")


class SearchRequest(BaseModel):
    """搜索请求"""
    query: str = Field(..., description="搜索查询")
    search_type: str = Field("hybrid", description="搜索类型：hybrid/es/semantic")
    top_k: int = Field(5, description="返回结果数量", ge=1, le=20)


class SearchResult(BaseModel):
    """搜索结果"""
    content: str
    source: str
    score: float
    type: Optional[str] = None


class SearchResponse(BaseModel):
    """搜索响应"""
    results: List[SearchResult]
    total: int
    query: str

